// 文件IO 读取文件

#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

#include <unistd.h>

int main(int argc, char *argv[])
{
    if (argc < 2) {
        printf("请传入要打开的文件路径\n");
        return -1;
    }
    int fd = open(argv[1], O_RDONLY);

    if (-1 == fd) {
        perror("open");
        return -1;
    }

    size_t read_num = 100;
    ssize_t res;
    char buf[100] = {0};
    
    res = read(fd, buf, read_num);
    
    if (res == -1) {
        perror("read");
        return -1;
    }

    printf("%s\n", buf);

    if (-1 == close(fd)) {
        perror("close");
        return -1;
    }

    return 0;
}
